using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

//等待进入游戏场景
public class PrepareState : ISceneState
{
    Button playBtn;
    GameObject obj;
    GameObject names;//名字和等级
    public PrepareState(SceneMgr sceneMgr) : base(sceneMgr)
    {
        this.SceneName = "Prepare";
    }
    public override void StateBegin()
    {
        playBtn=UITool.GetUIComponent<Button>("Tap To Start");
        obj=GameObject.Instantiate(Resources.Load<GameObject>("snake"));
        obj.transform.position=Vector3.zero;

        names=GameObject.Instantiate(Resources.Load<GameObject>("lv"),obj.transform);

        if(playBtn!=null)
        {
            playBtn.onClick.AddListener(()=>{
                m_SceneMgr.SetScene(new PlayState(m_SceneMgr),"Play");
                GameObject.DontDestroyOnLoad(obj);
                GameObject.DontDestroyOnLoad(names);
            });
        }
    }
    public override void UpDateScene()
    {
        names.transform.position=Camera.main.WorldToScreenPoint(obj.transform.position+Vector3.up);
    }
    public override void StateEnd()
    {

    }
}
